package com.yy.controller;

import com.yy.pojo.Dept;
import com.yy.pojo.Result;
import com.yy.service.DeptService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
public class DeptController {

    @Autowired
    private DeptService deptService;
//    private static Logger log = LoggerFactory.getLogger(DeptController.class);

    @GetMapping("/depts")
    public Result list(){

        log.info("查询全部部门数据");

        List<Dept> deptList = deptService.list();

        return Result.success(deptList);
    }

    /**
     *删除部门
     * @return
     */
    @DeleteMapping( "/depts")
    public Result delete(Integer id){
        log.info("根据id删除部门：{}",id);

        deptService.delete(id);

        return Result.success();
    }

    @PostMapping("/depts")
    public Result add(@RequestBody Dept dept){
        log.info("{}添加成功",dept);
        deptService.add(dept);
        return Result.success();
    }
}
